#include "demoobject.h"
#include <QDebug>
#include <QEventLoop>
#include <iostream>
#include <QTimer>

DemoObject::DemoObject(QObject *parent)
    : QObject(parent)
{

//    QTimer::singleShot(10000, this, [&](){
//       std::cout << "now will send  12, 13" << std::endl;
//       send_send_add_request(12, 13);
//    });
}

void DemoObject::send_send_add_request(int a, int b)
{
    QEventLoop e;
    Q_EMIT send_add_request(a, b);
    int rr;
    connect(this, &DemoObject::call, [&](int r) {
        std::cout << "quit!" << std::endl;
        rr = r;
        e.quit();
    });
    e.exec();
    std::cout << "after send_add_request rr: " << rr << std::endl;
}

void DemoObject::setVersion(const QString &version)
{
    m_version = version;
    std::cout << "set version " << version.toStdString() << std::endl;

//    send_send_add_request(4,5);

}

int DemoObject::test_add(int a, int b)
{
    return a + b;
}

QString DemoObject::getVersion()
{
    return m_version;
}

void DemoObject::Call(int r)
{
    std::cout << "call called" << std::endl;
    Q_EMIT call(r);
}
